{
  BlaiseWave library source file

  Remarks:
    - Default 'Shutdown' implementation does nothing.
    - Default 'Startup' function returns any non-nil pointer for success.
    - The default 'UserNames' array is empty, so the user name will be
      the same as the server name for a minimal server.

  Based on LWSDK library source files which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


uses
  {$IFDEF WINDOWS}
  SystemExceptionHandling,
  {$ENDIF}

  LW_Module,
  LW_Server,

  PlugIn   ;

var
  ServerDesc   : array [Byte] of TServerRecord;
  _mod_descrip : ModuleDescriptor;

exports _mod_descrip;

procedure FreeHandlers(Data, Arg : Pointer);
begin
  Dispose(PServerRecord(Data));
end;

procedure Shutdown(ServerData : Pointer);
begin
  if Assigned(HandlersList) then
  begin
    HandlersList.ForEachCall(@FreeHandlers, nil);
    HandlersList.Free;
  end;
end;

function Startup : Pointer;
var
  Index : Integer;
begin
  if Assigned(HandlersList) then
    for Index := 0 to HandlersList.Count - 1 do
      ServerDesc[Index] := TServerRecord(HandlersList.Items[Index]^);

  Result := Pointer(4);
end;

begin
  _mod_descrip.SysSync    := MOD_SYSSYNC;
  _mod_descrip.SysVersion := MOD_SYSVER ;
  _mod_descrip.SysMachine := MOD_MACHINE;
  _mod_descrip.Startup    := @Startup   ;
  _mod_descrip.Shutdown   := @Shutdown  ;
  _mod_descrip.ServerDefs := @ServerDesc;
end.
